package cn.cdyx.common.utils;

import cn.cdyx.common.pojo.Code;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Author Watermelon
 * @Date 2023-02-09 19:24
 */
public class DateTimeUtil {
    /**
     * YYYY-MM-DD hh:mm:ss 转  YYYY-MM-DD 00:00:00
     * @return
     */
    public static Date YDHLDate(Date ADate){
        Instant instant = ADate.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        LocalDateTime newDateTime = localDateTime.withHour(0).withMinute(0).withSecond(0).withNano(0);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Code.SYSTEM_DATATIME_PATTERN);
        SimpleDateFormat format = new SimpleDateFormat(Code.SYSTEM_DATATIME_PATTERN);
        Date date = Date.from(newDateTime.atZone(ZoneId.systemDefault()).toInstant());
        return date;
    }
}
